import { ref } from 'vue';

interface User {
  email: string;
  password: string;
}

export const loginUser = ref<User>({ email: '', pasword: '' });

interface Rules {
  email: {
    type: string;
    message: string;
    required: boolean;
    trigger: string;
  }[];
  password: (
    | {
        message: string;
        required: boolean;
        trigger: string;
        min?: undefined;
        max?: undefined;
      }
    | {
        min: number;
        max: number;
        message: string;
        trigger: string;
        required?: undefined;
      }
  )[];
}

// 校验规则
export const rules = ref<Rules>({
  email: [
    {
      type: 'email',
      message: 'Email is incorrect...',
      required: true,
      trigger: 'blur',
    },
  ],
  password: [
    {
      required: true,
      message: 'Password could not be empty...',
      trigger: 'blur',
    },
    {
      min: 6,
      max: 30,
      message: "Password's length has to be 6 to 30 characters...",
      trigger: 'blur',
    },
  ],
});
